import { getGameInfo } from "../api/gameapi";
import router from '../router'
export default {
  namespaced: true,
  state() {
    return {
      itemindex: null,
      orderlist: [],
      takelist: {},
      gameIdList: [],
      gameServerList: [],
      GameSysList: [],
      detailInfo: null,
      screenlist: [
        { id: 10, title: '价格', class: 'price', List: ['不限', '1~50元', '51~100元', '101~300元', '301~500元', '500元以上', '自定义'] },
        { id: 11, title: '初始段位', class: 'init', List: ['不限', '青铜', '白银', '黄金', '白金', '钻石', '星耀', '王者'] },
        { id: 12, title: '目标段位', class: 'global', List: ['不限', '青铜', '白银', '黄金', '白金', '钻石', '星耀', '王者'] },
      ],
      items: [
        {
          text: "游戏",
          children: [],
        },
        {
          text: "游戏区",
          children: [],
        },
        {
          text: "游戏区服",
          children: [],
        },
      ],
    }
  },
  getters: {
    itemListInfo(state) {
      let l = state.detailInfo
      console.log(l);
    }
  },
  mutations: {
    //列表模块
    initList(state, initdata) {
      // console.log(initdata);
      // console.log(initdata.takeOrderList);
      state.orderlist = initdata.takeOrderList
      state.orderlist.forEach(obj => {
        let arr = obj.totalPrice.split('￥')
        // console.log(parseInt(arr[1]));
        obj.totalPrice = parseInt(arr[1])
      })
    },
    initListMut(state, list) {
      // console.log(list);
      state.orderlist = list.takeOrderList
      state.orderlist.forEach(obj => {
        let arr = obj.totalPrice.split('￥')
        // console.log(parseInt(arr[1]));
        obj.totalPrice = parseInt(arr[1])
      })
      // console.log(state.orderlist);
    },

    // 游戏筛选模块
    getGameIdMut(state, list) {
      // console.log('id', list.games);
      state.gameIdList = list.games
      list.games.forEach(obj => {
        state.items[0].children.text = obj.GAME_NAME
        state.items[0].children.id = obj.GAME_ID
        state.items[0].children.push({ id: state.items[0].children.id, text: state.items[0].children.text })
      })
      // state.items[0].children = list.games
    },
    getGameSysMut(state, systemlist) {
      // console.log(systemlist);
      // console.log(state.items);
      state.GameSysList = systemlist
      systemlist.forEach(obj => {
        state.items[1].children.text = obj.areaName
        state.items[1].children.id = obj.areaId
        state.items[1].children.push({ id: state.items[1].children.id, text: state.items[1].children.text })
      })
    },
    getGameServerMut(state, serverlist) {
      // console.log(serverlist);
      state.gameServerList = serverlist
      serverlist.forEach(obj => {
        state.items[2].children.text = obj.serverName
        state.items[2].children.id = obj.serverId
        state.items[2].children.push({ id: state.items[2].children.id, text: state.items[2].children.text })
      })
      // state.items[2].children = list
    },
    getIndexMut(state, index) {
      state.itemindex = index
      // console.log(state.itemindex);
    },
    getDetailInfoMut(state, info) {
      // console.log(info);
      // console.log(info.bondAndTrainTime);
      // state.detailInfo = info
      let arr = info.bondAndTrainTime.split(" ")
      let pricetxt = arr[0].split('"')
      let price = pricetxt[0].split("：")[1]
      let timetxt = arr[2].split('"')
      let timenum = timetxt[0].split("：")[1]
      let time = timenum.split("小时")[0]
      let money = price / 2
      let arr2 = info.publiserInfo.split('"')
      let ordername = arr2[0].split('：')[1]
      console.log(arr2, ordername);
      // let money = moneytxt[0].split("")[1]
      // console.log(pricetxt, timetxt, price, time);
      state.detailInfo = {
        price: info.totalPrice,
        time: time,
        money: money,
        gameInfo: info.gameInfo,
        ordername: ordername,
        takeOrderTitle: info.takeOrderTitle,
        wechatOrder: info.wechatOrder,
        playerAccount: info.takeOrderId,
        wechatOrder: info.wechatOrder,
        devtime: '2天前'
      }
      // console.log(state.detailInfo);
    }
  },
  actions: {
    initListAct(context, list) {
      context.commit('initList', list)
    },
    getListAct(context, list) {
      context.commit('initListMut', list)
    },
    getGameIdAct(context, res) {
      let gameIdList = res.data
      context.commit('getGameIdMut', gameIdList)
    },
    getGameSysListAct(context, Syslist) {
      let getGameSysList = Syslist.data
      context.commit('getGameSysMut', getGameSysList)
    },
    getGameServerAct(context, res) {
      let gameServerList = res.data
      context.commit('getGameServerMut', gameServerList)
    },
    getGameDetailInfoAct(context) {
      // getGameInfo(47695927).then(res => {
      //   console.log(res);
      // })
      // console.log(111);
    }
  }
}